//package xyz.xtt.pay.mq;
//
//import cn.hutool.json.JSONUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.rocketmq.common.message.MessageExt;
//import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
//import org.apache.rocketmq.spring.core.RocketMQListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.context.config.annotation.RefreshScope;
//import org.springframework.stereotype.Component;
//import xyz.xtt.pay.api.dto.PayAttach;
//import xyz.xtt.pay.client.response.TblPayOrderDto;
//import xyz.xtt.pay.entity.TblAsset;
//import xyz.xtt.pay.entity.TblMissAsiaPk;
//import xyz.xtt.pay.mapper.TblMissAsiaPkMapper;
//import xyz.xtt.pay.service.IBlindBoxService;
//import xyz.xtt.pay.service.ITblAssetService;
//
//import java.nio.charset.StandardCharsets;
//import java.util.List;
//import java.util.Objects;
//
///**
// * 三方售卖玫瑰后续操作
// *
// * @author dale
// * @since 2024/12/30
// **/
//@RefreshScope
//@Slf4j
//@Component
//@RocketMQMessageListener(topic = "${rocketmq.pay.order.status.change.topic:nft_pay_order_status_change}", selectorExpression = "ASSET_WITH_PHYSICAL:PAY_SUCCESS", consumerGroup = "${rocketmq.consumer.group.missAsia.blindBox}")
//public class MissAsiaBlindBoxConsumer implements RocketMQListener<MessageExt> {
//	@Autowired
//	private IBlindBoxService iBlindBoxService;
//	@Autowired
//	ITblAssetService iTblAssetService;
//	@Autowired
//	TblMissAsiaPkMapper tblMissAsiaPkMapper;
//
//	@Override
//	public void onMessage(MessageExt msg) {
//		String msgId = msg.getMsgId();
//		int reconsumeTimes = msg.getReconsumeTimes();
//		String message = new String(msg.getBody(), StandardCharsets.UTF_8);
//		log.info("MissAsiaBlindBoxConsumer msgId:{},reconsumeTimes:{},message: {}", msgId, reconsumeTimes, message);
//		if (StringUtils.isEmpty(message)) {
//			return;
//		}
//		if (!JSONUtil.isTypeJSON(message)) {
//			log.warn("MissAsiaBlindBoxConsumer Received message: {} is not json", message);
//			return;
//		}
//		try {
//			TblPayOrderDto payOrderDto = JSONUtil.toBean(message, TblPayOrderDto.class);
//			if (Objects.isNull(payOrderDto)) {
//				log.warn("MissAsiaBlindBoxConsumer JSONUtil.toBean is null. message:{}", message);
//				return;
//			}
//			boolean openBox = iBlindBoxService.openBox(payOrderDto);
//			// pk实时更新热度值-wq
//			updateHotness(payOrderDto);
//			log.info("payOrderDto id:{},result:{}", payOrderDto.getPayOrderId(), openBox);
//		} catch (Exception e) {
//			log.info("MissAsiaBlindBoxConsumer consume failed. message:{} ex:{}", message, e.getMessage(), e);
//			throw new RuntimeException("MissAsiaBlindBoxConsumer Consumer Message exception", e);
//		}
//	}
//
//	/**
//	 * 实时更新热度值 String goodsId, String amount
//	 */
//	public void updateHotness(TblPayOrderDto payOrderDto) {
//		try {
//			PayAttach payAttach = JSONUtil.toBean(payOrderDto.getBusinessAttach(), PayAttach.class);
//			String goodsId = payAttach.getGoodsId();
//			String amount = payOrderDto.getOrderMoney().toString();
//			// 判断goodsId是不是属于亚姐
//			TblAsset tblAsset = iTblAssetService.assetInfoWithGoodsId(goodsId);
//			if (tblAsset == null || tblAsset.getFirstType() != 60) {
//				return;
//			}
//			// 查询发起者该资产现存正在pk的记录
//			List<TblMissAsiaPk> challengerList = tblMissAsiaPkMapper.findChallengerList(goodsId);
//			for (TblMissAsiaPk entity : challengerList) {
//				int sumAmount = Integer.parseInt(entity.getChallengerHotness()) + Integer.parseInt(amount);
//				// 更新记录的热力值
//				tblMissAsiaPkMapper.updateChallengerHotness(String.valueOf(entity.getId()), Integer.toString(sumAmount));
//			}
//			// 查询接受者该资产现存正在pk的记录
//			List<TblMissAsiaPk> acceptorList = tblMissAsiaPkMapper.findAcceptorList(goodsId);
//			for (TblMissAsiaPk entity : acceptorList) {
//				int sumAmount = Integer.parseInt(entity.getAcceptorHotness()) + Integer.parseInt(amount);
//				// 更新记录的热力值
//				tblMissAsiaPkMapper.updateAcceptorHotness(String.valueOf(entity.getId()), Integer.toString(sumAmount));
//			}
//		} catch (Exception e) {
//			log.info("updateHotness ex:{}", e.getMessage(), e);
//		}
//	}
//}
